﻿@{
    ViewBag.Title = "BestIframeAction";
}
@section HeaderContent{
    <script type="text/javascript" src="/Scripts/jquery.tmpl.min.js"></script>
    <script type="text/javascript">
        var index = 1;
        function openBrowse() {
            var iframe;
            iframe = document.getElementById("ifu").contentWindow.document;
            console.log(iframe);
            iframe.getElementById("file" + index).click();
            index++;
            $(iframe).find("div").append($("#fileInput_Item_Template").tmpl({ "index": index }));
        }
        function onupload() {
            var iframe;
            iframe = document.getElementById("ifu").contentWindow.document;
            iframe.getElementById("btnSubmit").click();
            index = 1;
        }
    </script>
    <script type="text/html" id="fileInput_Item_Template">
        <input id="file${index}" type="file" name="file" class="hide" />
    </script>
}
<h2>
    使用Iframe上传文件，都兼容</h2>
<input type="button" onclick="javascript:openBrowse();" value="增加文件" />
<input type="button" value="上传" onclick="onupload()" />
<iframe src="@Url.Action("Upload", "Home")" frameborder="0" id="ifu" name="ifu" scrolling="no">
</iframe>
